package com.eastmelon.tcp;

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author Administrator
 *如果URL没有指定端口那么 默认就是返回-1   port=80
 *
 *URL 对象有两个方法
 *1.openConnection
 *2.openStreanm:openConnection().getInputStream
 */
public class UrlDemo {
	public static void main(String[] args) throws Exception {
		URL url=new URL("http://blog.eastmelon.cn/search/超找.do");
		System.out.println(url.getHost());
		System.out.println(url.getPort());
		System.out.println(url.getPath());
		System.out.println(url.getFile());
		System.out.println(url.getQuery());
//		URLConnection uc=url.openConnection();
//		InputStream in=uc.getInputStream();
		InputStream in=url.openStream();
		byte[] buf=new byte[1024];
		int len=0;
		while((len=in.read(buf))!=-1){
			System.out.println(new String(buf,0,len));
		}
	}

}
